package com.neusoft.dibuy.lib.str;


import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class MyStr {
    public static void main(String[] args) {
        Calendar calendar =Calendar.getInstance();
        calendar.add(Calendar.MONTH,-1);
        Date date =   calendar.getTime()  ;
        date =new Date( calendar.getTimeInMillis() );
        SimpleDateFormat format =new SimpleDateFormat("yyyy-MM-dd");
        System.out.println( format.format(date) );
    }
    public static void main7(String[] args) throws ParseException {
        SimpleDateFormat format =new SimpleDateFormat("yyyy-MM-dd");
        Date  begin  =  format.parse("2020-01-01");
        Date  end   =  format.parse("2024-10-01");
        long  l   =  (  end.getTime() - begin.getTime() );
        l = l / (1000 *86400);
        System.out.println(l);
    }

    public static void main6(String[] args) {
//        Date d = new Date();
//        System.out.println(d.getTime());
//        LocalDateTime dt  =  LocalDateTime.now();
//        System.out.println(dt.format(DateTimeFormatter.ofPattern("yyyy年MM月dd日 hh:mm:ss") ));
//        LocalDateTime dt1 =  dt.plusDays(1000);
//        System.out.println(  dt1);
//        LocalDateTime d1 = LocalDateTime.parse("2020-01-01", DateTimeFormatter.ofPattern("yyyy-M-d"));
//
//        LocalDateTime d2 = LocalDateTime.parse("2024-10-11", DateTimeFormatter.ofPattern("yyyy-MM-dd"));
//        Duration duration = Duration.between(d1,d2);
//        System.out.println(duration.toDays());
//        LocalDateTime d1 = LocalDateTime.now();
//        System.out.println( d1.format(DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT)));
//        Loc
//        LocalDate start = LocalDate
//
//       String[] ss =  "2020-01-01".split("-");

//        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
//        LocalDateTime time = LocalDateTime.now();
//        String localTime = df.format(time);
//        String begin = "2020-01-01";
//        begin+= " 12:01:01";
//        String end = "2024-10-01";
//        end+= " 12:01:01";
//        LocalDateTime ldbegin = LocalDateTime.parse(begin,df);
//        LocalDateTime ldend  = LocalDateTime.parse(end,df);
//        Duration duration = Duration.between(ldbegin,ldend);
//        System.out.println(duration.toDays());
    }

    public static void main5(String[] args) {
        String s ="asdfgh";
        String ss =   s.substring(2,4);// [2,4)
        System.out.println(ss );

//        String s ="  123 41 234   ";
//        System.out.println(s.trim());

//        String s ="20,24-8-2,7";
//        String[] ss =   s.split("-,");
//
//        int i = 1;
    }
    public static void main4(String[] args) {
        String s ="abcbcbca";
        s.replace("bc", "ab");
        System.out.println(s.replace('b', '*'));
    }
    public static void main3(String[] args) {

        String str=null;
        str=String.format("Hi, %s"  ,  "王力");
        System.out.println(str);
        str=String.format("Hi,%s:%s.%s", "王南","王力","王张");
        System.out.println(str);
        System.out.printf("字母a的大写是：%c %n", 'A');
        System.out.printf("3>7的结果是：%b %n", 3>7);
        System.out.printf("100的一半是：%d %n", 100/2);
        System.out.printf("100的16进制数是：%x %n", 100);
        System.out.printf("100的8进制数是：%o %n", 100);

//        System.out.printf("50元的书打8.5折扣是：%f 元%n", 50*0.85);
//        System.out.printf("上面价格的16进制数是：%a %n", 50*0.85);
//        System.out.printf("上面价格的指数表示：%e %n", 50*0.85);
//        System.out.printf("上面价格的指数和浮点数结果的长度较短的是：%g %n", 50*0.85);
        System.out.printf("上面的折扣是%d%% %n", 85);
        System.out.printf("字母A的散列码是：%h %n", 'A');
        System.out.printf("字母A的散列码是：%tT %n",  new Date());

//       只有我们不知道方法，没有类库未提供方法；
//        String s1 ="aaa";
//        String s2="AAA";
//        System.out.println(s1.equalsIgnoreCase(s2));

//        String s = "12345678";
//        String s1 =   String.copyValueOf(s.toCharArray(),2,2);
//        System.out.println(s1);
    }
    public static void main2(String[] args) {
        String s ="abcasasdfaweasdasdfasdfasdfsadfadsfadsade";
        int sum = 0 ;
        char C ='a';
        int index = -1;
        do {
              index =  s.indexOf(C , index+1);
              sum++;
        }while (index != -1);
        sum--;

        System.out.println(sum);
    }

//  字面量： 1,2，“asdfasdf” --- 》  编译，   常量池 拘留池
//    new  堆
//    栈内存 - 4 , 8 ;
    public static void main1(String[] args) {
        String s ="abcasasdfaweasdasdfasdfasdfsadfadsfadsade";
        int sum = 0 ;
        char C ='a';
        for (int i = 0; i <s.length() ; i++) {
            char c =  s.charAt(i);
            if (c == C){
                sum ++;
            }
        }
        System.out.println(sum);



//        StringBuilder, StringBuffer
//        StringBuilder sb =new StringBuilder();
//        String s = "";
//        for (int  i  = 0;  i  < 1000;  i ++) {
//            sb.append("1");
//        }
//        System.out.println(sb.toString());

//        String s =new String("123"); //  byte[]
//        s =new String("456");

//        int  i  =123;
//        String  s =null  ;  // null --  >  0
//        s = new String("123");
        // 4G

        //  ; = new String("123");
//        String s ="123";
//        String s1 ="123";
//
//
//        String s2 =new String(s);
//        System.out.println(s==s1);
//        System.out.println(s==s2);
//        System.out.println(s.equals(s1));
//        System.out.println(s.equals(s2));
    }
}
